package com.demomaster.quickcompat.listener;

import android.view.View;


/**
 * VIEW 禁止重复点击事件
 */
public abstract class OnSingleClickListener implements View.OnClickListener {

    private long clickInterval = 1000;//两次间隔
    private long lastClickTime = 0;

    @Override
    public void onClick(View v) {
        long currentTimeMillis = System.currentTimeMillis();
        if (currentTimeMillis - lastClickTime > clickInterval) {
            onClickEvent(v);
            lastClickTime = currentTimeMillis;
        } else if (currentTimeMillis < lastClickTime) {
            lastClickTime = currentTimeMillis;
        }
    }

    public abstract void onClickEvent(View v);

    /**
     * 设置两次点击间隔
     *
     * @param clickInterval
     */
    public void setClickInterval(long clickInterval) {
        this.clickInterval = clickInterval;
    }
    public OnSingleClickListener(long clickInterval) {
        this.clickInterval = clickInterval;
    }
    public OnSingleClickListener() {
    }
}
